<?php
class AcademicosController extends AppController {

	var $name = 'Academicos';

	function index() {
		//Verificacion de sesion del sistema		
		if(!$this->Access->getMy('username')){
			$this->Session->setFlash(__('Por favor inicie sesion', true));
			$this->redirect(array('controller'=>'convocatorias','action' => 'publicaciones'));
		}
		$this->Academico->recursive = 0;
		$this->set('academicos', $this->paginate());
	}

	function view($id = null) {
		//Verificacion de sesion del sistema		
		if(!$this->Access->getMy('username')){
			$this->Session->setFlash(__('Por favor inicie sesion', true));
			$this->redirect(array('controller'=>'convocatorias','action' => 'publicaciones'));
		}
		if (!$id) {
			$this->Session->setFlash(__('Invalid academico', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('academico', $this->Academico->read(null, $id));
	}

	function add() {
		//	Verificacion de sesion del sistema		
		if(!$this->Access->getMy('username')){
			$this->Session->setFlash(__('Por favor inicie sesion', true));
			$this->redirect(array('controller'=>'convocatorias','action' => 'publicaciones'));
		}
		if (!empty($this->data)) {
			$this->Academico->create();
			if ($this->Academico->save($this->data)) {
				$this->Session->setFlash(__('The academico has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The academico could not be saved. Please, try again.', true));
			}
		}
		$perfiles = $this->Academico->Perfile->find('list');
		$this->set(compact('perfiles'));
	}

	function edit($id = null) {
		//	Verificacion de sesion del sistema		
		if(!$this->Access->getMy('username')){
			$this->Session->setFlash(__('Por favor inicie sesion', true));
			$this->redirect(array('controller'=>'convocatorias','action' => 'publicaciones'));
		}
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid academico', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Academico->save($this->data)) {
				$this->Session->setFlash(__('The academico has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The academico could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Academico->read(null, $id);
		}
		$perfiles = $this->Academico->Perfile->find('list');
		$this->set(compact('perfiles'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for academico', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Academico->delete($id)) {
			$this->Session->setFlash(__('Academico deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Academico was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>